<?php

namespace App\Http\Controllers\Admin;

use App\Models\Orm\AwAuditRecord;
use App\Models\Orm\CooperativeCompany;
use App\Models\Orm\Product;
use App\Models\Orm\ProductAudit;
use App\Models\Orm\ProductLabels;
use App\Models\Orm\ProjectProduct;
use App\Models\Orm\Recommand;
use App\Models\Orm\Recommend;
use App\Models\Orm\SecondsKill;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;

/**
 * 产品模块控制器
 *
 * Class ProductController
 * @package App\Http\Controllers\Admin
 */
class RecommandController extends Controller
{
    /**
     * 产品列表(展示页)
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $user = auth('admin')->user();

        $data = Recommand::with('product')->orderby('id', SORT_DESC)->get();
        return view('admin.recommand.index', compact('data'));

    }

    /**
     * 新建产品审核
     *
     * @return \Illuminate\Http\Response
     */
    public function create(Request $request)
    {
        $user = auth('admin')->user();

        if ($request->isMethod('post')) {

            $request->flash();
            $productIds = $request->input('product_id');
            foreach($productIds as $key=>$value)
            {
                $data['product_id'] = intval($value);
                Recommand::insert($data);
            }
            return redirect('/admin/recommand/index')->with(['success' => '您的申请已提交,请耐心等等待审核']);
        }

        $data = new Recommand();
        return view('admin.recommand.create', compact('data'));
    }



    /**
     * 修改产品详情审核
     *
     * @param  int $id
     * @return \Illuminate\Http\Response
     */
    public function delete(Request $request, $id)
    {
        Recommand::destroy($id);
        return redirect('/admin/recommand/index')->with(['info' => '删除成功']);
    }





}
